import TYPE from "../type";

import {getCart,delCart} from "../../api/cart"

export function getCartData(id){
    return dispatch=>{
        getCart(id).then(res=>{
            dispatch({
                type:TYPE.GET_CART,
                data:res.data.data
            })
        })
    }
}

export function delCartByQuery(){
    return {
        type:TYPE.DEL_bY_QUERY
    }
}




export function delCartItem(id){
    return dispatch=>{
        delCart(id).then(res=>{
            if(res.data.code===0){
                dispatch({
                   type:TYPE.DEL_CART_ITEM,
                   id:id
                })
            }
            
        })
    }
  
}

export function addCartItem(){
    return {
        type:TYPE.ADD_CART_ITEM
    }
}

export function checkCartItem(id){
    return {
        type:TYPE.CHECK_CART_ITEM,
        id:id
    }
}

export function addItemNum(id){
    return {
        type:TYPE.ADD_ITEM_NUM,
        id:id
    }
}

export function subItemNum(id){
    return {
        type:TYPE.SUB_ITEM_NUM,
        id:id
    }
}


export function allcheckItem(){
    return {
        type:TYPE.ALLCHECK_ITEM
    }
}







